package com.xy.mainp.utils;

import android.content.Context;

import com.xy.mainp.config.NetAPI;
import com.xy.net.OkHttpUtils;

import java.io.IOException;

/**
 * Created by John on 2016/11/2.
 */

public class NetRequestUtils {
    private static NetRequestUtils mInstance;
    private final OkHttpUtils httpUtils;

    private NetRequestUtils(Context context){
        httpUtils = OkHttpUtils.getInstance(context);
    }
    public static NetRequestUtils getInstance(Context context){
        if (mInstance == null) {
            synchronized (OkHttpUtils.class) {
                if (mInstance == null) {
                    mInstance = new NetRequestUtils(context);
                }
            }
        }
        return mInstance;
    }


    public void getIP(String url, boolean isCache, OkHttpUtils.ResultCallBack resultCallBack) {
        httpUtils.asynGet(NetAPI.IP_URL,true,resultCallBack);
    }

    public void getHomeData(String type, String count, String page, OkHttpUtils.ResultCallBack resultCallBack){
        httpUtils.asynGet(NetAPI.getHomeDataUrl(type,count,page),true,resultCallBack);
    };

    /**
     *  获取花瓣网搜索数据
     * @param q  关键字
     * @param category  分类
     * @param page  页码
     * @param prePage 每页总数
     * @param wlf  。。。不知道干嘛 默认为1
     * @param resultCallBack
     * @throws IOException
     */
    public void getHuaBanData(String q,String category ,String page,String prePage,String wlf,OkHttpUtils.ResultCallBack resultCallBack) throws IOException {
        httpUtils.asynGet(NetAPI.getHuabanDataUrl(q,category,page,prePage,wlf),true,resultCallBack);
    };

    /**
     * 获取花瓣网分类数据
     * @param qAndCategory
     * @param resultCallBack
     */
    public void getHuaBanData(String qAndCategory,OkHttpUtils.ResultCallBack resultCallBack)  {
        httpUtils.asynGet(NetAPI.getHuabanDataUrl(qAndCategory),true,resultCallBack);
    };

    /**
     * 获取笔趣网数据
     * @param resultCallBack
     */
    public void getBiQuData(OkHttpUtils.ResultCallBack resultCallBack){
        httpUtils.asynGet(NetAPI.BIQU_BASE_URL,true,resultCallBack);
    }

    /**
     * 获取笔趣网分类数据
     * @param category
     * @param resultCallBack
     */
    public void getBiQuData(String category,OkHttpUtils.ResultCallBack resultCallBack){
        httpUtils.asynGet(NetAPI.getBiQuDataUrl(category),true,resultCallBack);
    }
}
